package com.dubbo.test.curator.zk;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.data.Stat;

/**
 *  curator 客户端
 *  zj:  curatorFramework client___ start\getData\setData
 */
public class CuratorDemo {

    public static void main1(String[] args) throws Exception {
        CuratorFramework curatorFramework=CuratorFrameworkFactory.
                builder().connectString("127.0.0.1:2181").
                sessionTimeoutMs(4000).retryPolicy(new
                ExponentialBackoffRetry(1000,3)).
                namespace("curator").build();

        curatorFramework.start();

//        curatorFramework.create().creatingParentsIfNeeded().
//                withMode(CreateMode.PERSISTENT).
//                forPath("/xsd/node1","1".getBytes());

        Stat stat=new Stat();
        curatorFramework.getData().storingStatIn(stat).forPath("/xsd/node1");

        curatorFramework.setData().
                withVersion(stat.getVersion()).forPath("/xsd/node1","xx".getBytes());

        curatorFramework.close();


    }
}
